<?php

	// ADMIN PAGES
	require_once('theme_options/general_settings.php');
	require_once('theme_options/front_page_options.php');
	require_once('theme_options/slider_options.php');
	require_once('theme_options/blog_options.php');
	require_once('theme_options/portfolio_options.php');
	require_once('theme_options/content_scroller_options.php');
	require_once('theme_options/contact_page.php');
	require_once('theme_options/sidebars_options.php');
	require_once('theme_options/footer_options.php');
	
	require_once('includes/wordpress_reset_functions.php');
	
	// WIDGET AREAS
	require_once('includes/widget_areas.php');
	
	// SHORTCODES & GALLERIES
	require_once('includes/shortcode_manager/shortcode_manager.php');
	require_once('includes/shortcodes.php');
	require_once('includes/gallery.php');
	
	// ADS Lightbox rel
	add_filter( 'wp_get_attachment_link' , 'add_lighbox_rel' );
	function add_lighbox_rel( $attachment_link ) {
		if( strpos( $attachment_link , 'a href') != false && strpos( $attachment_link , 'img src') != false )
			$attachment_link = str_replace( 'a href' , 'a rel="prettyPhoto" href' , $attachment_link );
		return $attachment_link;
	}

	// WIDGETS
	require_once('theme_options/widgets/archive_widget.php');
	require_once('theme_options/widgets/contact_widget.php');
	require_once('theme_options/widgets/gallery_widget.php');
	require_once('theme_options/widgets/recent_comments_widget.php');
	require_once('theme_options/widgets/recent_posts_widget.php');
	require_once('theme_options/widgets/slideshow_widget.php');
	require_once('theme_options/widgets/twitter_widget.php');

	// META
	require_once('includes/meta_box_class.php');		
	require_once('includes/meta.php');	

	//PORTOFLIOS
	include_once('includes/portfolios_post_types.php');
	
	//LOCALIZATION
	load_theme_textdomain( 'reFresh', get_template_directory() . '/languages' );
	


if ( !is_admin() )
{
	function my_scripts_method()
	{
		
		wp_deregister_script('jquery');
	
		//REMOVE THE ADMIN BAR
		add_filter( 'show_admin_bar', '__return_false' );
		remove_action( 'init', 'wp_admin_bar_init' );
		
		$path = get_template_directory_uri();
	
		wp_enqueue_script("jquery", $path."/js/jquery.min.js", false, null);
		wp_enqueue_script("jquery_scripts", get_template_directory_uri()."/js/jquery.scripts.js", false, null);
		wp_enqueue_script("jquery_ui", get_template_directory_uri()."/js/jquery-ui-1.8.16.custom.min.js", false, null);
		wp_enqueue_script("jquery_jtransform", $path."/js/jquery.jqtransform.js", false, null);
		wp_enqueue_script("pretty_photo", $path."/js/prettyPhoto/js/jquery.prettyPhoto.js", false, null);
		wp_enqueue_script("swfobject", $path."/js/piecemaker/jquery.swfobject.js", false, null);
		
		
		wp_enqueue_script("jcarousel", $path."/js/jquery.jcarousel.js", false, null);
		wp_enqueue_script("jquery-isotope", get_template_directory_uri()."/js/jquery.isotope.min.js", false, null);
		
		
		
		if (get_option('font_active') == 'cufon')
		{
			wp_enqueue_script("cufon_js", $path."/js/cufon-yui.js", false, null);
		
			wp_enqueue_script("cufon_quicksand_book", $path."/js/cufon/Quicksand_Book_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'aller_light') wp_enqueue_script("cufon_aller_light", $path."/js/cufon/Aller_Light_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'aller_regular') wp_enqueue_script("cufon_aller", $path."/js/cufon/Aller_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'aurulent_sans') wp_enqueue_script("cufon_aurulent_sans", $path."/js/cufon/Aurulent_Sans_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'cantarell') wp_enqueue_script("cufon_cantarell", $path."/js/cufon/Cantarell_500.font.js", false, null);
			if (get_option('cufon_font_selection') == 'capture_it') wp_enqueue_script("cufon_capture_it", $path."/js/cufon/Capture_it_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'caviar_dreams') wp_enqueue_script("cufon_caviar_dreams_300", $path."/js/cufon/Caviar_Dreams_300.font.js", false, null);
			if (get_option('cufon_font_selection') == 'caviar_dreams_bold') wp_enqueue_script("cufon_caviar_dreams_500", $path."/js/cufon/Caviar_Dreams_500.font.js", false, null);
			if (get_option('cufon_font_selection') == 'centabel_book') wp_enqueue_script("cufon_centabel_book", $path."/js/cufon/Centabel_Book_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'colaborate_light') wp_enqueue_script("cufon_colaborate_light", $path."/js/cufon/ColaborateLight_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'colaborate_regular') wp_enqueue_script("cufon_colaborate_regular", $path."/js/cufon/Colaborate-Regular_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'colaborate_thin') wp_enqueue_script("cufon_colaborate_thin", $path."/js/cufon/Colaborate-Thin_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'district_thin') wp_enqueue_script("cufon_district_thin", $path."/js/cufon/DistrictThin_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'garogier') wp_enqueue_script("cufon_garogier", $path."/js/cufon/Garogier_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'geosans_light') wp_enqueue_script("cufon_geo_sans_light", $path."/js/cufon/GeosansLight_500.font.js", false, null);
			if (get_option('cufon_font_selection') == 'josefin') wp_enqueue_script("cufon_josefin_sans_std", $path."/js/cufon/Josefin_Sans_Std_300.font.js", false, null);
			if (get_option('cufon_font_selection') == 'oregon') wp_enqueue_script("cufon_oregon_ldo", $path."/js/cufon/Oregon_LDO_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'quicksand_book') wp_enqueue_script("cufon_quicksand_book", $path."/js/cufon/Quicksand_Book_400.font.js", false, null);
			if (get_option('cufon_font_selection') == 'quicksand_light') wp_enqueue_script("cufon_quicksand_light", $path."/js/cufon/Quicksand_Light_300.font.js", false, null);
			if (get_option('cufon_font_selection') == 'sansation_light') wp_enqueue_script("cufon_sansation_300", $path."/js/cufon/Sansation_300.font.js", false, null);
			if (get_option('cufon_font_selection') == 'ubuntu') wp_enqueue_script("cufon_ubuntu", $path."/js/cufon/Ubuntu_400.font.js", false, null);
			
			wp_enqueue_script("cufon_replacement_js", $path."/js/cufon_replacement.js", false, null);
		}
		
		
		// SLIDER SCRIPTS
		if (get_option('slider_active') == 'yes')
		{
			if (get_option('slider_selection') == 'anything_slider') wp_enqueue_script("anything_slider", $path."/js/jquery.anythingslider.js", false, null);
			
			if (get_option('slider_selection') == 'anything_video')
			{
				wp_enqueue_script("anything_slider", $path."/js/jquery.anythingslider.js", false, null);
				wp_enqueue_script("anything_video", $path."/js/jquery.anythingslider.video.js", false, null);
			}
			
			if (get_option('slider_selection') == 'wide_slider')
			{
				wp_enqueue_script("wide_slider", $path."/js/wide_slider/jquery.configurableSlider.js", false, null);
				wp_enqueue_script("engine", $path."/js/wide_slider/engine_fashion.js", false, null);
			}
			
			if (get_option('slider_selection') == 'accordion_slider') wp_enqueue_script("accordion_slider", $path."/js/jquery.kwicks-1.5.1.js", false, null);
		}
		
		// NIVO SLIDER ### for the front_page slider   AND   Slider Shortcode AND BX for CONTENT SCROLLER
		wp_enqueue_script("nivo_slider", $path."/js/nivo/jquery.nivo.slider.js", false, null);
		wp_enqueue_script("bx_slider", get_template_directory_uri()."/js/jquery.bxSlider.min.js", false, null);
		
		// Reply right after the comment rather than at the bottom of the comment list
		if ( is_singular() && get_option( 'thread_comments' ) )
			wp_enqueue_script( 'comment-reply' );

		
	}  // END function my_scripts_method()
	
	add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
	
	
} // END if ( !is_admin() )


	function admin_warnings() 
	{
		$warnings = '';
		if (!function_exists('bcn_display')) $warnings .= '<i>Warning:</i> "Breadcrumb NavXT" plugin is not installed or activated. Please install or activate.'; 
		
		if (!function_exists('wp_pagenavi'))
		{
			if ( $warnings != '' ) $warnings .= '<br />';
			$warnings .= '<i>Warning:</i> "WP-PageNavi" plugin is not installed or activated. Please install or activate.';      
		}     
		
		$absolute_path = __FILE__;
		$path_to_file = explode( 'wp-content', $absolute_path );
		$path_to_wp = $path_to_file[0];
		$theme_path = get_template_directory_uri();
		$website_url = site_url().'/';
		$theme_path = str_replace($website_url,'', $theme_path);
		$cache_path = $path_to_wp.$theme_path.'/includes/cache/';
		
		if (!is_writable($cache_path)) 
		{
			if ( $warnings != '' ) $warnings .= '<br />';
			$warnings .= '<i>Warning:</i> The cache folder is not writable! Please make the folder "wp-content/themes/theme_name/includes/cache" writable.';
		}
		
		return $warnings;
	}
	
	add_filter('widget_title', 'do_shortcode');
	add_filter('widget_text', 'do_shortcode');
	
	add_theme_support( 'post-thumbnails' );
	add_filter( 'show_admin_bar', '__return_false' );
	

	// AFTER THE TEMPLATE SETUP
	add_action( 'after_setup_theme', 'template_setup' );
	
	if ( ! function_exists( 'template_setup' ) )
	{
		function template_setup()
		{
			// This theme styles the visual editor with editor-style.css to match the theme style.
			add_editor_style();
		
			// This theme uses post thumbnails
			add_theme_support( 'post-thumbnails' );
		
			// Add default posts and comments RSS feed links to head
			add_theme_support( 'automatic-feed-links' );
		}
	}



	// if you want to use it in the theme settings or something like that
	if ( is_admin() )
	{
		function my_admin_scripts_method()
		{
			// Admin CSS
			wp_register_style('admin_css', get_template_directory_uri().'/css/admin.css');
			wp_enqueue_style('admin_css');
			
			wp_register_style('jqtransform', get_template_directory_uri().'/jqtransformplugin/jqtransform.css');
			wp_enqueue_style('jqtransform');
			
			wp_enqueue_script('media-upload');
			wp_register_script('custom_tb', get_template_directory_uri().'/js/thickbox.js', array('thickbox') );
			
			wp_enqueue_script('custom_tb');
			wp_enqueue_script('thickbox');
			wp_enqueue_style('thickbox');
		
			
			wp_enqueue_script('jquery colorpicker', get_template_directory_uri().'/js/colorpicker/js/colorpicker.js', false, null);
			wp_enqueue_script("jquery-jtransform", get_template_directory_uri()."/js/jquery.jqtransform.js", false, null);
			
			wp_deregister_script('jquery-ui');
			wp_enqueue_script("jquery-ui", get_template_directory_uri()."/js/jquery-ui-1.8.16.custom.min.js", false, null);
		}  
		
		add_action( 'admin_enqueue_scripts', 'my_admin_scripts_method' );
	} // END if ( is_admin() )




////////////////////

function RGB_TO_HSV ($R, $G, $B)  // RGB Values:Number 0-255 
{                                 // HSV Results:Number 0-1 
   $HSL = array(); 

   $var_R = ($R / 255); 
   $var_G = ($G / 255); 
   $var_B = ($B / 255); 

   $var_Min = min($var_R, $var_G, $var_B); 
   $var_Max = max($var_R, $var_G, $var_B); 
   $del_Max = $var_Max - $var_Min; 

   $V = $var_Max; 

	$max = 0;
	$H = 0;
	$S = 0;
	
   if ($del_Max == 0) 
   { 
      $H = 0; 
      $S = 0; 
   } 
   else 
   { 
      $S = $del_Max / $var_Max; 

      $del_R = ( ( ( $max - $var_R ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max; 
      $del_G = ( ( ( $max - $var_G ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max; 
      $del_B = ( ( ( $max - $var_B ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max; 

      if      ($var_R == $var_Max) $H = $del_B - $del_G; 
      else if ($var_G == $var_Max) $H = ( 1 / 3 ) + $del_R - $del_B; 
      else if ($var_B == $var_Max) $H = ( 2 / 3 ) + $del_G - $del_R; 

      if ($H<0) $H++; 
      if ($H>1) $H--; 
   } 

   $HSL['H'] = $H; 
   $HSL['S'] = $S; 
   $HSL['V'] = $V; 

   return $HSL; 
} 

function HSV_TO_RGB ($H, $S, $V)  // HSV Values:Number 0-1 
{                                 // RGB Results:Number 0-255 
    $RGB = array(); 

    if($S == 0) 
    { 
        $R = $G = $B = $V * 255; 
    } 
    else 
    { 
        $var_H = $H * 6; 
        $var_i = floor( $var_H ); 
        $var_1 = $V * ( 1 - $S ); 
        $var_2 = $V * ( 1 - $S * ( $var_H - $var_i ) ); 
        $var_3 = $V * ( 1 - $S * (1 - ( $var_H - $var_i ) ) ); 

        if       ($var_i == 0) { $var_R = $V     ; $var_G = $var_3  ; $var_B = $var_1 ; } 
        else if  ($var_i == 1) { $var_R = $var_2 ; $var_G = $V      ; $var_B = $var_1 ; } 
        else if  ($var_i == 2) { $var_R = $var_1 ; $var_G = $V      ; $var_B = $var_3 ; } 
        else if  ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2  ; $var_B = $V     ; } 
        else if  ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1  ; $var_B = $V     ; } 
        else                   { $var_R = $V     ; $var_G = $var_1  ; $var_B = $var_2 ; } 

        $R = $var_R * 255; 
        $G = $var_G * 255; 
		$B = $var_B * 255; 
    } 

    $RGB['R'] = $R; 
    $RGB['G'] = $G; 
    $RGB['B'] = $B; 

    return $RGB; 
}


function process_color($unprocessed_color, $type)
{
	$rTotal = substr($unprocessed_color, 0, 2);
	$gTotal = substr($unprocessed_color, 2, 2);
	$bTotal = substr($unprocessed_color, 4, 2);

	$rTotal = base_convert($rTotal, 16, 10);
	$gTotal = base_convert($gTotal, 16, 10);
	$bTotal = base_convert($bTotal, 16, 10);
	
	$getArrayHSB = RGB_TO_HSV($rTotal, $gTotal, $bTotal);
	
	if($type == 'anything')
	{
		$saturation = 1.5; //[0,10]
		if ( $getArrayHSB['S'] < 0.2 )$saturation = 5; //[0,10]
		if ( $getArrayHSB['S'] < 0.3 )$saturation = 3; //[0,10]
		if ( $getArrayHSB['S'] < 0.4 )$saturation = 2; //[0,10]
		
		$class =' dot_15';
		$text_class = 'text2';
		if ( $getArrayHSB['V'] > 0.5 )
		{ 
			$class = ' dot_30';
			$text_class = 'text3';
		}
		
		$getArrayHSB['S'] = $saturation*$getArrayHSB['S'];
		$getArrayHSB['S'] = max(0.0,min($getArrayHSB['S'],1.0)); 
	}


	if($type == 'nivo')
	{
		$saturation = 1.3; //[0,10]

		if ( $getArrayHSB['S'] < 0.6 ) $saturation = 1.3; //[0,10]
		if ( $getArrayHSB['S'] < 0.5 ) $saturation = 1.4; //[0,10]
		if ( $getArrayHSB['S'] < 0.4 ) $saturation = 1.5; //[0,10]
		if ( $getArrayHSB['S'] < 0.3 ) $saturation = 2; //[0,10]
		if ( $getArrayHSB['S'] < 0.2 ) $saturation = 3; //[0,10]
		
		$brightness = 1;
		if ( $getArrayHSB['V'] < 0.7 ) $brightness = 1.1;
		if ( $getArrayHSB['V'] < 0.6 ) $brightness = 1.3;
		if ( $getArrayHSB['V'] < 0.5 ) $brightness = 1.5;
		if ( $getArrayHSB['V'] < 0.4 ) $brightness = 2;
		if ( $getArrayHSB['V'] < 0.3 ) $brightness = 2.6;
		if ( $getArrayHSB['V'] < 0.2 ) $brightness = 3.9;
		if ( $getArrayHSB['V'] < 0.1 ) $brightness = 7;
		
		$getArrayHSB['S'] = $saturation * $getArrayHSB['S'];
		$getArrayHSB['S'] = max(0.0, min($getArrayHSB['S'], 1.0)); 
		
		$getArrayHSB['V'] = $brightness * $getArrayHSB['V'];
		$getArrayHSB['V'] = max(0.0, min($getArrayHSB['V'], 1.0)); 
	}
	
	
	$getArrayRGB = HSV_TO_RGB($getArrayHSB['H'],$getArrayHSB['S'],$getArrayHSB['V']);
	 
	$getArrayRGB['R'] = (int)$getArrayRGB['R'];
	$getArrayRGB['G'] = (int)$getArrayRGB['G'];
	$getArrayRGB['B'] = (int)$getArrayRGB['B'];
	 
	$var_R = $getArrayRGB['R'];
	$var_G = $getArrayRGB['G'];
	$var_B = $getArrayRGB['B'];
	 
	$var_R = base_convert($getArrayRGB['R'], 10, 16);
	$var_G = base_convert($getArrayRGB['G'], 10, 16);
	$var_B = base_convert($getArrayRGB['B'], 10, 16);
	
	if ( base_convert($var_R, 16, 10) < 16 ) $var_R = '0'.$var_R;
	if ( base_convert($var_G, 16, 10) < 16 ) $var_G = '0'.$var_G;
	if ( base_convert($var_B, 16, 10) < 16 ) $var_B = '0'.$var_B;
	
	$resulting_color = $var_R;
	$resulting_color .= $var_G;
	$resulting_color .= $var_B;
	
	return $resulting_color;
}



###############     write_slider BEGIN     ###############

function write_slider($type)
{
	function select_slides()
	{
		global $wpdb;
		$display_slides_query = 'SELECT * FROM `'.$wpdb->prefix.'lazar_slider` WHERE `active` = 1 ORDER BY position';
		$display_slides = $wpdb->get_results($display_slides_query);
		return $display_slides;
	}
	
	$display_slides = select_slides();
	
	$count_slides = 0;
	$count_slides = count($display_slides);
	
	if ( $type == 'anything_slider' )
	{   ###############     anything slider BEGIN     ###############
		
		$slider = '<section id="slider" class = "mk_function_slider" style="margin-bottom: 40px !important;">';
		
			$anything_slider_height = get_option('anything_slider_height', '385');
			if ( $anything_slider_height == '' ) $anything_slider_height = '385';
			
			$anything_slider_height = str_replace( 'px', '', $anything_slider_height );
			
			$slider .= '<ul class="anything_slider_ul clearfix" style="height: '.$anything_slider_height.'px !important;">';
			
			foreach ( $display_slides as $slide )
			{
				$slider .= '<li>';
					//begin colores
					
					if ( get_option('slider_color') == 'individual_color' && $slide->img_original_color != '' )
					{
						if ( $slide->img_original_color	== $slide->img_color )
							$caption_color = process_color($slide->img_original_color, 'nivo');
							
						else 
							$caption_color = $slide->img_color;
					}
					else 
						$caption_color = get_option('theme_color');
					
					// end colores		
						
					if ( $slide->target == 'link' && $slide->link != 'no_link' )
					{
						$slider .= '<a href="'.$slide->link.'">';
						$link_exists = true;
					}
					
					if ( $slide->target == 'image' && $slide->img != 'no_image' )
					{
						$slider .= '<a href="'.$slide->img.'">';
						$link_exists = true;
					}
					
					if ( $slide->target == 'video' && $slide->video != 'no_video' )
					{
						$slider .= '<a href="'.$slide->video.'">';
						$link_exists = true;
					}
					
					$slider .= '<div class="anything_read_more">';
						$slider .= '<div class="square" style="background-color: #'.$caption_color.' !important;">';
							$slider .= '<div class="arrow"></div>';
						$slider .= '</div>';
						$slider .= '<div class="read_more_text">Read More</div>';
					$slider .= '</div>';
					
					$slider .= '<img src="';
					$slider .= get_template_directory_uri();
					$slider .= '/includes/timthumb.php?src=';
					$slider .= $slide->img;
					$slider .= '&amp;h='.$anything_slider_height.'&amp;w=960&amp;zc=1&amp;q=100"';
					$slider .= ' alt="'.$slide->title.'" />';
					
					if ( $link_exists )
					{
						$slider .= '</a>';
					}
				$slider .= '</li>';
			}
			$slider .= '</ul>';
		$slider .= '</section>';
	
	}     ///////////////     anything slider END     ///////////////
	
	
	if ( $type == 'anything_video' )
	{   ###############     anything video BEGIN     ###############
		
		$slider = '<section id="slider" class = "mk_function_slider" style="margin-bottom: 40px !important;">';
		
			$anything_slider_height = get_option('anything_slider_video_height', '530');
			if ( $anything_slider_height == '' ) $anything_slider_height = '530';
			
			$anything_slider_height = str_replace( 'px', '', $anything_slider_height );
			
			$slider .= '<ul class="anything_slider_ul clearfix" style="height: '.$anything_slider_height.'px !important;">';
			
			foreach ( $display_slides as $slide )
			{
				$slider .= '<li>';
				
					if ( $slide->video == 'no_video' )
					{
						//begin colores
						
						$text_class = '';
						$class = '';
						$link_exists = false;
						
						$class =' dot_15';
						$text_class = 'text2';
							if ( get_option('slider_color') == 'individual_color' && $slide->img_original_color != '' )
							{
								if ( $slide->img_original_color	== $slide->img_color )
									$caption_color = process_color($slide->img_original_color, 'nivo');
									
								else 
									$caption_color = $slide->img_color;
							}
							else 
								$caption_color = get_option('theme_color');
						
						// end colores		
							

						if ( $slide->target == 'link' && $slide->link != 'no_link' )
						{
							$slider .= '<a href="'.$slide->link.'">';
							$link_exists = true;
						}
						
						if ( $slide->target == 'image' && $slide->img != 'no_image' )
						{
							$slider .= '<a href="'.$slide->img.'">';
							$link_exists = true;
						}
						
						if ( $slide->target == 'video' && $slide->video != 'no_video' )
						{
							$slider .= '<a href="'.$slide->video.'">';
							$link_exists = true;
						}
						
						$slider .= '<div class="anything_read_more">';
							$slider .= '<div class="square" style="background-color: #'.$caption_color.' !important;">';
								$slider .= '<div class="arrow"></div>';
							$slider .= '</div>';
							$slider .= '<div class="read_more_text">Read More</div>';
						$slider .= '</div>';
						
						$slider .= '<img src="';
						$slider .= get_template_directory_uri();
						$slider .= '/includes/timthumb.php?src=';
						$slider .= $slide->img;
						$slider .= '&amp;h='.$anything_slider_height.'&amp;w=960&amp;zc=1&amp;q=100"';
						$slider .= ' alt="'.$slide->title.'" />';
						
						if ( $link_exists )
						{
							$slider .= '</a>';
						}
					}
					else // if ( $slide->video != 'no_video' )
					{
						$slider .= html_entity_decode($slide->video);	
					}
					
				$slider .= '</li>';
			}
			$slider .= '</ul>';
		$slider .= '</section>';
	
	}     ///////////////     anything video END     ///////////////
	
	if ( $type == 'nivo_slider' )
	
	{
	###############     nivo slider BEGIN     ###############
		
	if ( get_option('nivo_thumbnails') == '' ) update_option('nivo_thumbnails','on');
	
		$slider_image_size = 'w=960&amp;h=385';
		
		$slider = '<section id="slider" class = "mk_function_slider" '; if ( get_option('nivo_thumbnails') == 'off' ) $slider.= ' style="margin-bottom: 40px !important;"'; $slider .= '>';
			$slider .= '<div id="slider_wrapper">';
				$slider .= '<div id="slider_content">'."\n";
				
					## the images
					foreach ( $display_slides as $slide )
					{
						$link_exists = false;
						if ( $slide->target == 'link' && $slide->link != 'no_link' )
						{
							$slider .= '<a href="'.$slide->link.'">';
							$link_exists = true;
						}
						
						if ( $slide->target == 'image' && $slide->img != 'no_image' )
						{
							$slider .= '<a href="'.$slide->img.'">';
							$link_exists = true;
						}
						
						if ( $slide->target == 'video' && $slide->video != 'no_video' )
						{
							$slider .= '<a href="'.$slide->video.'">';
							$link_exists = true;
						}
						
						$slider .= '<img src="'.get_template_directory_uri().'/includes/timthumb.php?src='.$slide->img.'&amp;'.$slider_image_size.'&amp;zc=1&amp;q=100" ';
						$slider .= 'alt="'.$slide->title.'" '; 
						if ( $slide->title != 'no_title' )
						{
							$slider .= 'title="#'.$slide->id.'" ';
						}
						$slider .= '/>';
						
						if ( $link_exists )
						{
							$slider .= '</a>';
						}
					}  // END foreach
					
				$slider .= '</div> <!-- end #slider_content -->';
				
				## the html captions ( the text on the slide )
				foreach ( $display_slides as $slide )  
				{
					if ( get_option('slider_color') == 'individual_color' && $slide->img_original_color != '' )
					{
						if ( $slide->img_original_color	== $slide->img_color )
							$caption_color = process_color($slide->img_original_color, 'nivo');
							
						else 
							$caption_color = $slide->img_color;
					}
					else 
						$caption_color = get_option('theme_color');
					
					if ( $slide->title != 'no_title' || $slide->text != 'no_text' )
					{
						$slider .= '<div id="'.$slide->id.'" class="nivo-html-caption">';
					}
					if ( $slide->title != 'no_title' ) $slider .= '<div class="caption_title" style="color: #'.$caption_color.' !important;">'.$slide->title.'</div>';
					if ( $slide->text != 'no_text' ) $slider .= '<div class="caption_text">'.html_entity_decode($slide->text).'</div>';
						
					if ( $slide->title != 'no_title' || $slide->text != 'no_text' )
					{
						$slider .= '</div> <!-- end #htmlcaption -->';
					}
				}  // END foreach 
			
			$slider .= '</div> <!-- end #slider_wrapper -->';
		
		## here we write the big thumbnails ( carousel )
		if ( get_option('nivo_thumbnails') == 'on' )  
		{
			$slider .= '<div id="thumbnail_carousel">';
				$slider .= '<div id="thumbnail_wrapper">';
					$slider .= '<div id="thumbnail_carousel_prev"></div>';
					$slider .= '<ul>';
	
						$thumbnail_counter = 0;
						foreach ( $display_slides as $slide )
						{
							$slider .= '<li>';
								$slider .= '<a class="nivo-control" rel="'.$thumbnail_counter.'" >';
									$slider .= '<img src="'.get_template_directory_uri().'/includes/timthumb.php?src='.$slide->img.'&amp;h=120&amp;w=96&amp;zc=1&amp;q=100" ';   // sau 72 x 128 (wide)
									$slider .= 'alt="'.$slide->title.'" />';
								$slider .= '</a>';
							$slider .= '</li>';
							
							$thumbnail_counter++;
						}
		
					$slider .= '</ul>';
					$slider .= '<div id="thumbnail_carousel_next"></div>';
				$slider .= '</div>';
			$slider .= '</div>';
		}
		
		## here we write the big thumbnails ( carousel )
		if ( get_option('nivo_thumbnails') == 'off' )  
		{
			$slider .= '<div class="nivo_small_thumbnails">';
				$thumbnail_counter = 0;
					foreach ( $display_slides as $slide )
					{
						$slider .= '<a rel="'.$thumbnail_counter.'" >';
							$slider .= $thumbnail_counter;
						$slider .= '</a>';
						
						$thumbnail_counter++;
					}
			$slider .= '</div>';
		}

		$slider .= '</section> <!-- end #slider -->';
		
	}
	///////////////     nivo_slider END     ///////////////
	
	
	if ( $type == 'bx_slider' )
	{   ###############     bx slider BEGIN     ###############
		
		$position_class = get_option('content_position', 'right_alignment');
		if ( $position_class == '' )
			$position_class = 'right_alignment';
		
		$bx_bg_class = ' bx_left_bg';
		if ( $position_class == 'right_alignment' )
			$bx_bg_class = ' bx_right_bg';
		
		$slider = '<section id="slider">';
			$slider .= '<div class="content_slider'.$bx_bg_class.'">';
				$slider .= '<ul class="bx_slider clearfix">';
				
				foreach ( $display_slides as $slide )
				{
					$slider .= '<li class="clearfix">';
						//begin colores
						
						if ( get_option('slider_color') == 'individual_color' && $slide->img_original_color != '' )
						{
							if ( $slide->img_original_color	== $slide->img_color )
								$caption_color = process_color($slide->img_original_color, 'nivo');
								
							else 
								$caption_color = $slide->img_color;
						}
						else 
							$caption_color = get_option('theme_color');
						
						// end colores		
						
						$button_type    = get_option('content_slider_button_type', 'link');
						
						$slider .= '<div class="bx_content_wrapper '.$position_class.'">';
							$slider .= '<div class="bx_content">';
								if ( $slide->title != 'no_title' ) $slider .= '<h3 style="color: #'.$caption_color.' !important;">'.$slide->title.'</h3>';
								if ( $slide->second_title != 'no_second_title' ) $slider .= '<h4>'.$slide->second_title.'</h4>';
								
								if ( $slide->text != 'no_text' ) $slider .= '<div class="content_text">'.html_entity_decode($slide->text).'</div>';
								
								if ( $slide->link != 'no_link' )
								{
									if ( $button_type ==  'link' )
									{		
										$slider .= '<div class="read_more">';
											$slider .= '<a href="'.$slide->link.'" style="color: #'.$caption_color.';">';
												$slider .= '<span class="read_more_arrow"></span>';
												$slider .= 'Read More';
											$slider .= '</a>';
										$slider .= '</div>';
									}
									
									if ( $button_type ==  'button' )
									{		
										$slider .= '<div class="read_more_button">';
											$slider .= '<a href="'.$slide->link.'" style="color: #'.$caption_color.';">';
												$slider .= 'Read More';
											$slider .= '</a>';
										$slider .= '</div>';
									}
								}
							
							$slider .= '</div>'; // end .bx_content
						$slider .= '</div>'; // end .bx_content_wrapper
						
						$slider .= '<img src="';
						$slider .= get_template_directory_uri();
						$slider .= '/includes/timthumb.php?src=';
						$slider .= $slide->img;
						$slider .= '&amp;h=385&amp;w=624&amp;zc=1&amp;q=100"';
						$slider .= ' alt="'.$slide->title.'" />';
					$slider .= '</li>';
				}
				$slider .= '</ul>';
				
			if ( get_option('layout_style', 'full_width') == 'boxed')
			{
				$button_prev_style = ' style="left: 336px;"';
				$button_next_style = '';
				
				if ( $position_class == 'right_alignment' )
				{
					$button_prev_style = '';
					$button_next_style = ' style="right: 336px;"';
				}
					
				$slider .= '<a class="bx-prev-boxed" href=""'.$button_prev_style.'>prev</a>';
				$slider .= '<a class="bx-next-boxed" href=""'.$button_next_style.'>next</a>';
			}
			
			else 
			{
				$slider .= '<a class="bx-prev" href="">prev</a>';
				$slider .= '<a class="bx-next" href="">next</a>';
			}
			
			$slider .= '</div> <!-- .content_slider -->';
		$slider .= '</section>';
	
	}     ///////////////     bx slider END     ///////////////
	
	
	if ( $type == 'carousel' )
	{
	###############     carousel BEGIN     ###############
	
		if ( get_option ('carousel_border') == 'off' || get_option('carousel_border') == '' )
			$carousel_class = 'big_carousel_no_border';
		else
			$carousel_class = 'big_carousel_with_border';
		
		$carousel_size = get_option('carousel_size');
		
		if ( $carousel_size == 'custom' )
		{
			$carousel_image_width  = get_option('carousel_width', '250');
			$carousel_image_height = get_option('carousel_height', '350');
			
			if ( $carousel_image_width  == '' ) $carousel_image_width  = 350;
			if ( $carousel_image_height == '' ) $carousel_image_height = 350;
			
			$carousel_image_width  = str_replace( 'px', '', $carousel_image_width );
			$carousel_image_height = str_replace( 'px', '', $carousel_image_height );
			
			$carousel_image_size = 'w='.$carousel_image_width.'&amp;h='.$carousel_image_height;
			
			$carousel_width  = (int)($carousel_image_width);
			$carousel_height = (int)($carousel_image_height);
		}
		
		else 
		{
			if ( $carousel_size == 'tall' )
			{
				$carousel_image_size = 'w=250&amp;h=350';
				$carousel_width  = '250';
				$carousel_height = '350';
			}
			if ( $carousel_size == 'square' )
			{
				$carousel_image_size = 'w=350&amp;h=350';
				$carousel_width  = '350';
				$carousel_height = '350';
			}
			if ( $carousel_size == 'wide' )
			{
				$carousel_image_size = 'w=500&amp;h=350';
				$carousel_width  = '500';
				$carousel_height = '350';
			}
		}
		
		if ( get_option('carousel_border') == 'on' )
		{
			$carousel_width  += 10;
			$carousel_height += 10;
		}

		$carousel_width_style  = 'style="width: '.$carousel_width.'px !important;"';
		$carousel_height_style = 'style="height: '.$carousel_height.'px !important;"';
		
		$slider = '<section id="slider">';
			$slider .= '<div id="big_carousel_wrapper">';
				$slider .= '<ul id="big_carousel" class="'.$carousel_class.'" '.$carousel_height_style.'>';
				
				foreach ( $display_slides as $slide )
				{
					//begin colores
					if ( get_option('slider_color') == 'individual_color' && $slide->img_original_color != '' )
					{
						if ( $slide->img_original_color	== $slide->img_color )
							$caption_color = process_color($slide->img_original_color, 'nivo');
							
						else 
							$caption_color = $slide->img_color;
					}
					else 
						$caption_color = get_option('theme_color');
					// end colores		
					
					$slider .= '<li '.$carousel_width_style.'>';
						$slider .= '<div class="content">';
						
							if ( $slide->target == 'link' && $slide->link != 'no_link' )
							{
								$slider .= '<a href="'.$slide->link.'">';
								$link_exists = true;
							}
							
							if ( $slide->target == 'image' && $slide->img != 'no_image' )
							{
								$slider .= '<a href="'.$slide->img.'">';
								$link_exists = true;
							}
							
							if ( $slide->target == 'video' && $slide->video != 'no_video' )
							{
								$slider .= '<a href="'.$slide->video.'">';
								$link_exists = true;
							}
							
							$slider .= '<div class="slide_image">';
								$slider .= '<img src="';
								$slider .= get_template_directory_uri();
								$slider .= '/includes/timthumb.php?src=';
								$slider .= $slide->img;
								$slider .= '&amp;'.$carousel_image_size.'&amp;zc=1&amp;q=100"';
								$slider .= ' alt="'.$slide->title.'" />';
								
								$slider .= '<div class="title" style="background-color: #'.$caption_color.' !important;"><h3>'.$slide->title.'</h3></div>';
							$slider .= '</div>';
							
							if ( $link_exists )
							{
								$slider .= '</a>';
							}
						$slider .= '</div>'; // end .content
					$slider .= '</li>';
				}
				$slider .= '</ul>';

				$slider .= '<a id="big_carousel_prev" href="#">prev</a>';
				$slider .= '<a id="big_carousel_next" href="#">next</a>';
			
			$slider .= '</div> <!-- end of #big_carousel_wrapper -->';
			
		$slider .= '</section>';
	}
	///////////////    carousel END     ///////////////
	
	
	###############     wide_slider BEGIN     ###############
	
	
	if ( $type == 'wide_slider' && count($display_slides) > 2 )
	{
		$wide_slider_img_size = 'h=280&amp;w=462';
		
		$slider = '<section id="slider" style="margin-bottom: 35px !important;">';
			$slider .= '<div class="wide_slider clearfix">';
				$slider .= '<ul>';
	
			$as_many_times = 0;
			$double_it = 1;
			if ( count($display_slides) == 3 || count($display_slides) == 4 ) $double_it++;
			
			while ( $as_many_times != $double_it ):
				for ( $i = count($display_slides)-2; $i < count($display_slides); $i++ )  // the last two 
				{
					$slider .= '<li>';
					
					//begin colores
					if ( get_option('slider_color') == 'individual_color' && $display_slides[$i]->img_original_color != '' )
					{
						if ( $display_slides[$i]->img_original_color == $display_slides[$i]->img_color )
							$caption_color = process_color($display_slides[$i]->img_original_color, 'nivo');
							
						else 
							$caption_color = $display_slides[$i]->img_color;
					}
					else 
						$caption_color = get_option('theme_color');
					//end colores	
										
						$slider .= '<div class="slide_image">';
							$slider .= '<img src="';
							$slider .= get_template_directory_uri();
							$slider .= '/includes/timthumb.php?src=';
							$slider .= $display_slides[$i]->img;
							$slider .= '&amp;'.$wide_slider_img_size.'&amp;zc=1&amp;q=100"';
							$slider .= ' alt="'.$display_slides[$i]->title.'" />';
						$slider .='</div>';
						
						$slider .= '<div class="info-container" style="display:none">';
							
							$slider .= '<div class="slide_title" style="color: #'.$caption_color.' !important;">';
								if ( $display_slides[$i]->title != 'no_title' ) $slider .= $display_slides[$i]->title;
								else $slider .= 'No Title';
							$slider .= '</div>';
							$slider .= '<div class="slide_description">';
								if ( $display_slides[$i]->text != 'no_text' ) $slider .= html_entity_decode($display_slides[$i]->text);
								else $slider .= 'No Description';
							$slider .= '</div>';
							if ( $display_slides[$i]->target == 'link' && $display_slides[$i]->link != 'no_link' )
							{
								$slider .= '<a href="'.$display_slides[$i]->link.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
							if ( $display_slides[$i]->target == 'image' && $display_slides[$i]->img != 'no_image' )
							{
								$slider .= '<a href="'.$display_slides[$i]->img.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
							if ( $display_slides[$i]->target == 'video' && $display_slides[$i]->video != 'no_video' )
							{
								$slider .= '<a href="'.$display_slides[$i]->video.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
						$slider .= '</div> <!-- end of .info-container -->';
					$slider .= '</li>';
				}
				
				for ( $i = 0; $i < count($display_slides)-2; $i++ )  //  from the first to the last ( except the last two )
				{
					$slider .= '<li>';
					
					//begin colores
					if ( get_option('slider_color') == 'individual_color' && $display_slides[$i]->img_original_color != '' )
					{
						if ( $display_slides[$i]->img_original_color == $display_slides[$i]->img_color )
							$caption_color = process_color($display_slides[$i]->img_original_color, 'nivo');
							
						else 
							$caption_color = $display_slides[$i]->img_color;
					}
					else 
						$caption_color = get_option('theme_color');
					//end colores	
					
						$slider .= '<div class="slide_image">';
							$slider .= '<img src="';
							$slider .= get_template_directory_uri();
							$slider .= '/includes/timthumb.php?src=';
							$slider .= $display_slides[$i]->img;
							$slider .= '&amp;'.$wide_slider_img_size.'&amp;zc=1&amp;q=100"';
							$slider .= ' alt="'.$display_slides[$i]->title.'" />';
						$slider .='</div>';
						
						$slider .= '<div class="info-container" style="display:none">';
							
							$slider .= '<div class="slide_title" style="color: #'.$caption_color.' !important;">';
								if ( $display_slides[$i]->title != 'no_title' ) $slider .= $display_slides[$i]->title;
								else $slider .= 'No Title';
							$slider .= '</div>';
							$slider .= '<div class="slide_description">';
								if ( $display_slides[$i]->text != 'no_text' ) $slider .= html_entity_decode($display_slides[$i]->text);
								else $slider .= 'No Description';
							$slider .= '</div>';
							if ( $display_slides[$i]->target == 'link' && $display_slides[$i]->link != 'no_link' )
							{
								$slider .= '<a href="'.$display_slides[$i]->link.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
							if ( $display_slides[$i]->target == 'image' && $display_slides[$i]->img != 'no_image' )
							{
								$slider .= '<a href="'.$display_slides[$i]->img.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
							if ( $display_slides[$i]->target == 'video' && $display_slides[$i]->video != 'no_video' )
							{
								$slider .= '<a href="'.$display_slides[$i]->video.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
	
						$slider .= '</div> <!-- end of .info-container -->';
					$slider .= '</li>';
				}
				
				$as_many_times++;
				
			endwhile;
			
				$slider .='</ul>';
			$slider .='</div> <!-- end of #fw_slider -->';
		$slider .='</section> <!-- end of #slider -->';
			
		$slider .= '<div id="wide_slider_frame">';
			$slider .= '<div id="wide_slider_tools_wrapper">';
				$slider .= '<div id="title_description">';
					$slider .= '<div class="project-slider">';
						$slider .= '<div class="info-container">';
							
							//begin colores
							if ( get_option('slider_color') == 'individual_color' && $display_slides[0]->img_original_color != '' )
							{
								if ( $display_slides[0]->img_original_color == $display_slides[0]->img_color )
									$caption_color = process_color($display_slides[0]->img_original_color, 'nivo');
									
								else 
									$caption_color = $display_slides[0]->img_color;
							}
							else 
								$caption_color = get_option('theme_color');
							//end colores	
							
							$slider .= '<div class="slide_title" style="color: #'.$caption_color.' !important;">';
								if ( $display_slides[0]->title != 'no_title' ) $slider .= $display_slides[0]->title;
								else $slider .= 'No Title';
							$slider .= '</div>';
							$slider .= '<div class="slide_description">';
								if ( $display_slides[0]->text != 'no_text' ) $slider .= html_entity_decode($display_slides[0]->text);
								else $slider .= 'No Description';
							$slider .= '</div>';
							
							if ( $display_slides[0]->target == 'link' && $display_slides[0]->link != 'no_link' )
							{
								$slider .= '<a href="'.$display_slides[0]->link.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
							if ( $display_slides[0]->target == 'image' && $display_slides[0]->img != 'no_image' )
							{
								$slider .= '<a href="'.$display_slides[0]->img.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
							if ( $display_slides[0]->target == 'video' && $display_slides[0]->video != 'no_video' )
							{
								$slider .= '<a href="'.$display_slides[0]->video.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
	
						$slider .= '</div> <!-- end of .info-container -->';
					$slider .= '</div> <!-- end of .project-slider -->';
				$slider .= '</div> <!-- end of #title_description -->';
				$slider .= '<div class="wide_slider_navi">';
					$slider .= '<a class="back"></a>';
					$slider .= '<a class="foward"></a>';
				$slider .= '</div>';
			$slider .= '</div> <!-- end of #wide_slider_tools_wrapper -->';
		$slider .= '</div> <!-- end of #wide_slider_frame -->';	
	}
	
	///////////////    wide_slider END     ///////////////


	if ( $type == 'piecemaker' )
	{
	###############     piecemaker BEGIN     ###############

		$slider = '<section id="slider" style="margin-bottom: 20px !important;">';
			$slider .= '<div id="piecemaker_wrapper">';
				$slider .= '<div id="piecemaker">';
					$slider .= '<p>';
						$slider .= 'You need to <a href="http://www.adobe.com/products/flashplayer/" target="_blank">upgrade your Flash Player</a> to version 10 or newer.';
					$slider .= '</p>';
				$slider .= '</div>';
			$slider .= '</div>';
		$slider .= '</section>';
	}
	///////////////    piecemaker END     ///////////////

	
	if ( $type == 'accordion_slider' && $count_slides >= 3 )
	{
	###############     accordion_slider BEGIN     ###############
		
		$slider = '<section id="slider">';
			$slider .= '<div id="accordion_slider">';		
				$slider .='<ul class="kwicks horizontal">';
	
				if ( $count_slides > 6 ) $count_slides = 6;
				$kwicks_displayed = 0;
						
				$number_of_elements_class = 'with_'.$count_slides.'_elements';
				
					foreach ( $display_slides as $slide )
					{
						
						/// colores start
						
						if ( get_option('slider_color') == 'individual_color' && $slide->img_original_color != '' )
						{
							if ( $slide->img_original_color	== $slide->img_color )
								$caption_color = process_color($slide->img_original_color, 'nivo');
								
							else 
								$caption_color = $slide->img_color;
						}
						else 
							$caption_color = get_option('theme_color');
						
						///  colores end
						
						$kwicks_displayed++;
						
						$slider .= '<li class="'.$number_of_elements_class.'">';
							if ( $slide->target == 'link' && $slide->link != 'no_link' )
							{
								$slider .= '<a href="'.$slide->link.'">';
								$link_exists = true;
							}
							
							if ( $slide->target == 'image' && $slide->img != 'no_image' )
							{
								$slider .= '<a href="'.$slide->img.'">';
								$link_exists = true;
							}
							
							if ( $slide->target == 'video' && $slide->video != 'no_video' )
							{
								$slider .= '<a href="'.$slide->video.'">';
								$link_exists = true;
							}
							
							// The Caption
							if ( $slide->title != 'no_title' || $slide->text != 'no_text' )
							{
								$slider .= '<div id="'.$slide->id.'" class="accordion_caption" style="opacity: 0;">';
									$slider .= '<div class="accordion_wrapper">';
							}
									if ( $slide->title != 'no_title' ) $slider .= '<div class="caption_title" style="color: #'.$caption_color.' !important;">'.$slide->title.'</div>';
									if ( $slide->text != 'no_text' ) $slider .= '<div class="caption_text">'.$slide->text.'</div>';
									
							if ( $slide->title != 'no_title' || $slide->text != 'no_text' )
							{
									$slider .= '</div>';
								$slider .= '</div> <!-- end #htmlcaption -->';
							}
												
							// The Image
							$slider .= '<div class="slide_image">';
								$slider .= '<img src="';
								$slider .= get_template_directory_uri();
								$slider .= '/includes/timthumb.php?src=';
								$slider .= $slide->img;
								$slider .= '&amp;h=385&amp;w=640&amp;zc=1&amp;q=100"';
								$slider .= ' alt="'.$slide->title.'" />';
							$slider .='</div>';
							
							if ( $link_exists )
							{
								$slider .= '</a>';
							}
						$slider .= '</li>';
						if ( $kwicks_displayed == $count_slides ) break;
					}
				$slider .= '</ul>';
			$slider .= '</div> <!-- end of #accordion_slider -->';
		$slider .= '</section> <!-- end of #slider -->';
	
	}
	///////////////    accordion_slider END     ///////////////
	
	
	if ( $type == 'complex_slider' && $count_slides >= 3 )
	{
	###############     complex_slider BEGIN     ###############
	
		$type = array( 1 => array( 
									0 => 'small',
									1 => 'small',
									2 => 'wide',
									3 => 'wide'
								   ),
					  
					   2 => array( 
									0 => 'big',
									1 => 'small',
									2 => 'small'
								   ),
					   
					   3 => array( 
									0 => 'wide',
									1 => 'small',
									2 => 'small',
									3 => 'wide'
								   ),
					   
					   4 => array( 
									0 => 'wide',
									1 => 'big'
								   ),
					   
					   5 => array( 
									0 => 'big',
									1 => 'wide'
								   ),
					   
					   6 => array( 
									0 => 'small',
									1 => 'small',
									2 => 'big'
								   ),
					   
					   7 => array( 
									0 => 'wide',
									1 => 'wide',
									2 => 'small',
									3 => 'small'
								   )
					  );
		
		$counter [0] = 4;
		$counter [1] = 3;
		$counter [2] = 4;
		$counter [3] = 2;
		$counter [4] = 2;
		$counter [5] = 3;
		$counter [6] = 4;
		
		$slider = '<section id="slider">';
			$slider .= '<div id="complex_slider">';
				$slider .= '<ul>';
			
				$type_counter = 0;
				$which_type = 1;
				
				$slides_added = 0;
				
				for($kkk=0; $kkk<5; $kkk++)
				foreach ( $display_slides as $slide )
				{
					if ( $type_counter % count($type[$which_type]) == 0 ) $slider .= '<li>';
					
						$element_class = $type[$which_type][$type_counter];
						$slider .=  '<div class="complex_element '.$element_class.'">';
							
							if ( $type[$which_type][$type_counter] == 'small' ) 
							{
								$thumbnail_size = 'w=158&amp;h=158';
								$item_size = 'width: 158px; height: 158px;';
							}
							
							if ( $type[$which_type][$type_counter] == 'wide' )
							{
								$thumbnail_size = 'w=318&amp;h=158';
								$item_size = 'width: 318px; height: 158px;';
							}
							
							if ( $type[$which_type][$type_counter] == 'big' )
							{
								$thumbnail_size = 'w=318&amp;h=318';
								$item_size = 'width: 318px; height: 318px;';
							}
							
							$image_source = get_template_directory_uri().'/includes/timthumb.php?src='.$slide->img.'&amp;'.$thumbnail_size.'&amp;zc=1&amp;q=100';
							$image_background_source = get_template_directory_uri().'/includes/timthumb.php?src='.$slide->img.'&amp;'.$thumbnail_size.'&amp;zc=1&amp;q=100&amp;f=2|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8';
							
							$slider .= '<a href="'.$slide->link.'" style="'.$item_size.'">';
								$slider .= '<div class="content_wrapper" style="'.$item_size.'">';
									$slider .= '<div class="content" style="'.$item_size.'">';
										$slider .= '<h4>';
											$slider .= $slide->title;
										$slider .= '</h4>';
										if ( $slide->second_title != 'no_second_title' )
										{
											$slider .= '<div class="text">';
												$slider .= $slide->second_title;
											$slider .= '</div>';
										}
									$slider .= '</div>';
								$slider .= '</div>';
								
								$slider .= '<img class="image" style="display: block; '.$item_size.'" src="'.$image_source.'" alt="'; 
								$slider .= get_the_title();
								$slider .= '" />';
							$slider .= '</a>';
							
						$slider .=  '</div>';
					if ( $type_counter % count($type[$which_type]) == count($type[$which_type]) - 1 || $slides_added == 5 * $count_slides - 1 ) $slider .= '</li>';
					
					$type_counter++;
					
					if ( $type_counter == count($type[$which_type]) )
					{
						$which_type++;
						$type_counter = 0;
					}
	
					if ( $which_type == 8 ) $which_type = 1;
					$slides_added++;
				}
			
				$slider .= '</ul>';
			$slider .= '</div> <!-- end of #complex_slider -->';
		$slider .= '</section>';
	
	}
	///////////////    complex_slider END     ///////////////
	
echo $slider;

}
///////////////     write_slider END     ///////////////


###############     content_scroller BEGIN     ###############
function content_scroller()
{
	$scroller_size = 'w=135&amp;h=115';

	echo '<section id="content_scroller_wrapper">';
		echo '<div id="content_scroller_top"></div>';
		if ( get_option('content_scroller_title') != '' )
		{
			echo '<div id="content_scroller_title">';
				echo get_option('content_scroller_title');
			echo '</div>';
		}
    	echo '<div id="content_scroller">';
        	echo '<div id="elements_wrapper">';
                echo '<ul id="mycarousel" class="jcarousel-skin-tango">';
				
					$current_categories = get_option('content_scroller_categories');
					$count_scroller = 0;
					$wp_query = new WP_Query('post_type=post&showposts=-1&cat='.$current_categories);
						
					if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
					
						if ( has_post_thumbnail() ) $thumbnail_src = wp_get_attachment_url( get_post_thumbnail_id(  ) ); // sters (the_ID())
						else $thumbnail_src = '';
						
						if ( get_option('content_scroller_elements_link') == 'image' )     { $link = $thumbnail_src;   $rel = ' rel="prettyPhoto"'; }
						if ( get_option('content_scroller_elements_link') == 'gallery' )   { $link = $thumbnail_src;   $rel = ' rel="prettyPhoto[content_slider]"'; }
						if ( get_option('content_scroller_elements_link') == 'permalink' ) { $link = get_permalink();  $rel = ''; }
						
						echo '<li>'; 
							echo '<a'; echo $rel; echo ' href="'; echo $link; echo '">';
								echo '<img src="'; echo get_template_directory_uri(); echo '/includes/timthumb.php?src='.$thumbnail_src.'&amp;'.$scroller_size.'&amp;zc=1&amp;q=100" alt="'; echo the_title(); echo'" />';
							echo '</a>';
						echo '</li>';
						
						$count_scroller++;
					endwhile; endif;

					if ( $count_scroller <= 4 ) $content_scroller_args = 'hide_buttons';
					else $content_scroller_args = '';
					
					update_option('content_scroller_args', $content_scroller_args);
               	echo '</ul>';
				
        	echo '</div> <!-- #elements_wrapper -->';
			
			if ( $count_scroller > 4 )
			{
				if ( get_option('layout_style', 'full_width') == 'full_width' )
					$content_scroller_buttons_class = ' class="arrows"';
				else $content_scroller_buttons_class = ' class="buttons"';
				
				echo '<a id="content_scroller_prev" href="#"'.$content_scroller_buttons_class.'></a>';
				echo '<a id="content_scroller_next" href="#"'.$content_scroller_buttons_class.'></a>';
			}
    	echo '</div> <!-- end #scroller_content -->';
		if ( get_option('content_scroller_description') != '' )
		{
			echo '<div id="content_scroller_description">';
				echo get_option('content_scroller_description');
			echo '</div>';
		}
		echo '<div id="content_scroller_bottom"></div>';
    echo '</section> <!-- end #content_scroller_wrapper" -->';

}
///////////////     content_scroller END     ///////////////


###############     main menu walker BEGIN     ###############

class description_walker extends Walker_Nav_Menu
{
      function start_el(&$output, $item, $depth, $args)
      {
           global $wp_query;
           $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

           $class_names = $value = '';

           $classes = empty( $item->classes ) ? array() : (array) $item->classes;

           $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
           $class_names = ' class="'. esc_attr( $class_names ) . '"';

           $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';

           $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
           $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
           $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
           $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';

           $prepend = '<strong>';
           $append = '</strong>';
           $description  = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';

           if($depth != 0)
           {
           		$description = $append = $prepend = "";
           }

           $item_output = $args->before;
           $item_output .= '<a'. $attributes .'>';
           $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
           $item_output .= $description.$args->link_after;
           $item_output .= '</a>';
           $item_output .= $args->after;

           $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
     }
}
///////////////     main menu walker END     ///////////////




/////////////////////////////////////////////
//                COMMENTS                 //
/////////////////////////////////////////////

if ( ! function_exists( 'comment_callback' ) )
{
	function comment_callback( $comment, $args, $depth ) {
		$GLOBALS['comment'] = $comment;
		switch ( $comment->comment_type ) :
			case '' :
		
        echo '<li '; comment_class(); echo ' id="comment-'; echo comment_ID(); echo '">';
            echo '<div class="comment_wrapper clearfix">';
            	echo '<div class="comment_left">';
                	echo '<div class="avatar-wrapper">';
						echo get_avatar( $comment, 76 );
                    echo '</div>';
                echo '</div>';
                echo '<div class="comment_right">';
               		echo '<div class="comment_meta">';
                        echo '<div class="comment_date">';
							the_time('g:i a'); echo '-'; the_time('F j, Y');
						echo '</div> ';
                        echo '<div class="comment_reply">';
							comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); 
                        echo '</div>';
                    echo '</div>';
                    
                    echo '<div class="comment_author">';
						echo get_comment_author_link();
                    echo '</div>';
                    
                    echo '<div class="comment_content">';
						comment_text();
                    echo '</div>';
                echo '</div>';
            echo '</div>';
          
				break;
			case 'pingback'  :
			case 'trackback' :
	  		?>
			<li class="post pingback">
			  <p>
				<?php __( 'Pingback:', 'reFresh' ); ?>
				<?php comment_author_link(); ?>
				<?php edit_comment_link( __('Edit', 'reFresh'), ' ' ); ?>
			  </p>
			  <?php
				break;
		endswitch;
	}
} // END if ( ! function_exists( 'comment_callback' ) )


/////////////////////////////////////////////
//           COMMENTS LABELS               //
/////////////////////////////////////////////

	add_filter('comment_form_default_fields', 'edit_the_comment_form');
	function edit_the_comment_form($arg)
	{
		if ( !isset($aria_req) ) $aria_req = '';
		$commenter = wp_get_current_commenter();
		
		$author_form = '<div class="form_input author_form">';
			$author_form .= '<label for="author">' . __( 'Name:', 'reFresh'  ) . '</label> ' . '<span class="required">*</span>';
			$author_form .= '<input class="required" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" tabindex="1"' . $aria_req . ' />';
		$author_form .= '</div>';
		
		$email_form = '<div class="form_input email_form">';
			$email_form .= '<label for="email">' . __( 'Email:', 'reFresh'  ) . '</label> ' . '<span class="required">*</span>';
			$email_form .= '<input class="required email" id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30" tabindex="2"' . $aria_req . ' />';
		$email_form .= '</div>';		
		
		$url_form = '<div class="form_input url_form">';
			$url_form .= '<label for="url">' . __( 'Website:', 'reFresh' ) . '</label>';
			$url_form .= '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" tabindex="3" />';
		$url_form .= '</div>';	
		
    	$arg['author'] = $author_form;
		$arg['email']  = $email_form;
    	$arg['url']    = $url_form;
		
    	return $arg;
	}	
	
	add_filter('comment_form_defaults', 'the_comment_field');
	function the_comment_field($arg)
	{
		$comment_form = '<div class="form_input comment_form">';
			$comment_form .= '<label for="comment">' . __( 'Comment:', 'reFresh'  ) . '</label>' . '<span class="required">*</span>';
			$comment_form .= '<textarea class="required" id="comment" name="comment" cols="45" rows="8" tabindex="4" aria-required="true"></textarea>';
		$comment_form .= '</div>';	
		
		$arg['comment_field'] = $comment_form;
		
    	return $arg;
	}
	
	add_filter('comment_form_defaults', 'the_comment_labels');
	function the_comment_labels($arg)
	{
		$arg['title_reply'] = __( 'Leave a reply', 'reFresh'  );
		$arg['title_reply_to'] = __( 'Leave a reply to %s', 'reFresh'  );
		$arg['cancel_reply_link'] = __( 'Cancel reply', 'reFresh'  );
		$arg['label_submit'] = __( 'Post Comment', 'reFresh'  );
		
		$arg['comment_notes_before'] = '';
		$required_text = __('Required fields are marked ', 'reFresh').'<span class="required">*</span>';
		$arg['comment_notes_after'] = '';
    	return $arg;
	}
	
	
/////////////////////////////////////////////
//               EXCERPT                   //
/////////////////////////////////////////////

function new_excerpt_more($more) {
	return '';
}
add_filter('excerpt_more', 'new_excerpt_more');
	
function new_excerpt_length($length) {
	return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');

function refresh_custom_excerpt_more( $output )
{
	if ( has_excerpt() && ! is_attachment() )
		$output .= 'Continue reading';

	return $output;
}
add_filter( 'get_the_excerpt', 'refresh_custom_excerpt_more' );



/////////////////////////////////////////////
//               Add BY Michael            //
/////////////////////////////////////////////




###############     write_slider BEGIN     ###############

function mk_write_slider($type)
{
	function select_slides()
	{
		global $wpdb;
		$display_slides_query = 'SELECT * FROM `'.$wpdb->prefix.'lazar_slider` WHERE `active` = 1 ORDER BY position';
		$display_slides = $wpdb->get_results($display_slides_query);
		return $display_slides;
	}
	
	$display_slides = select_slides();
	
	$count_slides = 0;
	$count_slides = count($display_slides);
	
	if ( $type == 'anything_slider' )
	{   ###############     anything slider BEGIN     ###############
		
		$slider = '<div id = "slider_out"><section id="slider" class = "mk_function_slider" style="margin-bottom: 40px !important;">';
		
			$anything_slider_height = get_option('anything_slider_height', '385');
			if ( $anything_slider_height == '' ) $anything_slider_height = '385';
			
			$anything_slider_height = str_replace( 'px', '', $anything_slider_height );
			
			$slider .= '<ul class="anything_slider_ul clearfix" style="height: '.$anything_slider_height.'px !important;">';
			
			foreach ( $display_slides as $slide )
			{
				$slider .= '<li>';
					//begin colores
					
					if ( get_option('slider_color') == 'individual_color' && $slide->img_original_color != '' )
					{
						if ( $slide->img_original_color	== $slide->img_color )
							$caption_color = process_color($slide->img_original_color, 'nivo');
							
						else 
							$caption_color = $slide->img_color;
					}
					else 
						$caption_color = get_option('theme_color');
					
					// end colores		
						
					if ( $slide->target == 'link' && $slide->link != 'no_link' )
					{
						$slider .= '<a href="'.$slide->link.'">';
						$link_exists = true;
					}
					
					if ( $slide->target == 'image' && $slide->img != 'no_image' )
					{
						$slider .= '<a href="'.$slide->img.'">';
						$link_exists = true;
					}
					
					if ( $slide->target == 'video' && $slide->video != 'no_video' )
					{
						$slider .= '<a href="'.$slide->video.'">';
						$link_exists = true;
					}
					
					$slider .= '<div class="anything_read_more">';
						$slider .= '<div class="square" style="background-color: #'.$caption_color.' !important;">';
							$slider .= '<div class="arrow"></div>';
						$slider .= '</div>';
						$slider .= '<div class="read_more_text">Read More</div>';
					$slider .= '</div>';
					
					$slider .= '<img src="';
					$slider .= get_template_directory_uri();
					$slider .= '/includes/timthumb.php?src=';
					$slider .= $slide->img;
					$slider .= '&amp;h='.$anything_slider_height.'&amp;w=750&amp;zc=1&amp;q=100"';
					$slider .= ' alt="'.$slide->title.'" />';
					
					if ( $link_exists )
					{
						$slider .= '</a>';
					}
				$slider .= '</li>';
			}
			$slider .= '</ul>';
		$slider .= '</section></div>';
	
	}     ///////////////     anything slider END     ///////////////
	
	
	if ( $type == 'anything_video' )
	{   ###############     anything video BEGIN     ###############
		
		$slider = '<section id="slider" class = "mk_function_slider" style="margin-bottom: 40px !important;">';
		
			$anything_slider_height = get_option('anything_slider_video_height', '530');
			if ( $anything_slider_height == '' ) $anything_slider_height = '530';
			
			$anything_slider_height = str_replace( 'px', '', $anything_slider_height );
			
			$slider .= '<ul class="anything_slider_ul clearfix" style="height: '.$anything_slider_height.'px !important;">';
			
			foreach ( $display_slides as $slide )
			{
				$slider .= '<li>';
				
					if ( $slide->video == 'no_video' )
					{
						//begin colores
						
						$text_class = '';
						$class = '';
						$link_exists = false;
						
						$class =' dot_15';
						$text_class = 'text2';
							if ( get_option('slider_color') == 'individual_color' && $slide->img_original_color != '' )
							{
								if ( $slide->img_original_color	== $slide->img_color )
									$caption_color = process_color($slide->img_original_color, 'nivo');
									
								else 
									$caption_color = $slide->img_color;
							}
							else 
								$caption_color = get_option('theme_color');
						
						// end colores		
							

						if ( $slide->target == 'link' && $slide->link != 'no_link' )
						{
							$slider .= '<a href="'.$slide->link.'">';
							$link_exists = true;
						}
						
						if ( $slide->target == 'image' && $slide->img != 'no_image' )
						{
							$slider .= '<a href="'.$slide->img.'">';
							$link_exists = true;
						}
						
						if ( $slide->target == 'video' && $slide->video != 'no_video' )
						{
							$slider .= '<a href="'.$slide->video.'">';
							$link_exists = true;
						}
						
						$slider .= '<div class="anything_read_more">';
							$slider .= '<div class="square" style="background-color: #'.$caption_color.' !important;">';
								$slider .= '<div class="arrow"></div>';
							$slider .= '</div>';
							$slider .= '<div class="read_more_text">Read More</div>';
						$slider .= '</div>';
						
						$slider .= '<img src="';
						$slider .= get_template_directory_uri();
						$slider .= '/includes/timthumb.php?src=';
						$slider .= $slide->img;
						$slider .= '&amp;h='.$anything_slider_height.'&amp;w=960&amp;zc=1&amp;q=100"';
						$slider .= ' alt="'.$slide->title.'" />';
						
						if ( $link_exists )
						{
							$slider .= '</a>';
						}
					}
					else // if ( $slide->video != 'no_video' )
					{
						$slider .= html_entity_decode($slide->video);	
					}
					
				$slider .= '</li>';
			}
			$slider .= '</ul>';
		$slider .= '</section>';
	
	}     ///////////////     anything video END     ///////////////
	
	if ( $type == 'nivo_slider' )
	
	{
	###############     nivo slider BEGIN     ###############
		
	if ( get_option('nivo_thumbnails') == '' ) update_option('nivo_thumbnails','on');
	
		$slider_image_size = 'w=753&amp;h=360';

		$left_nav = "<div id = 'mk_left_ul' ><ul>
		<li><a href='http://www.myfount.com'>Bussiness Card</a></li>
		<li><a href='http://www.myfount.com'>Bussiness Card</a></li>
		<li><a href='http://www.myfount.com'>Bussiness Card</a></li>
		<li><a href='http://www.myfount.com'>Bussiness Card</a></li>
		<li><a href='http://www.myfount.com'>Bussiness Card</a></li>
		<li><a href='http://www.myfount.com'>Bussiness Card</a></li>
		<li><a href='http://www.myfount.com'>Bussiness Card</a></li>
		<li><a href='http://www.myfount.com'>Bussiness Card</a></li>
		<li><a href='http://www.myfount.com'>Bussiness Card</a></li>
		</ul></div>";

		$left_nav = wp_nav_menu( array('menu' => 'slider_left' , 'echo' => false , 'container_id' => 'mk_left_ul' , 'theme_location' => 'slider_left')) ;

		$slider = $left_nav;

		$slider = '<section id="slider" class = "mk_function_slider" '; if ( get_option('nivo_thumbnails') == 'off' ) $slider.= ' style="margin-bottom: 40px !important;"'; $slider .= '>';
			
			$slider .= $left_nav;

			$slider .= '<div id = "slider_right" ><div id="slider_wrapper">';
				$slider .= '<div id="slider_content">'."\n";
				
					## the images
					foreach ( $display_slides as $slide )
					{
						$link_exists = false;
						if ( $slide->target == 'link' && $slide->link != 'no_link' )
						{
							$slider .= '<a href="'.$slide->link.'">';
							$link_exists = true;
						}
						
						if ( $slide->target == 'image' && $slide->img != 'no_image' )
						{
							$slider .= '<a href="'.$slide->img.'">';
							$link_exists = true;
						}
						
						if ( $slide->target == 'video' && $slide->video != 'no_video' )
						{
							$slider .= '<a href="'.$slide->video.'">';
							$link_exists = true;
						}
						
						$slider .= '<img src="'.get_template_directory_uri().'/includes/timthumb.php?src='.$slide->img.'&amp;'.$slider_image_size.'&amp;zc=1&amp;q=100" ';
						$slider .= 'alt="'.$slide->title.'" '; 
						if ( $slide->title != 'no_title' )
						{
							$slider .= 'title="#'.$slide->id.'" ';
						}
						$slider .= '/>';
						
						if ( $link_exists )
						{
							$slider .= '</a>';
						}
					}  // END foreach
					
				$slider .= '</div> <!-- end #slider_content -->';
				
				## the html captions ( the text on the slide )
				foreach ( $display_slides as $slide )  
				{
					if ( get_option('slider_color') == 'individual_color' && $slide->img_original_color != '' )
					{
						if ( $slide->img_original_color	== $slide->img_color )
							$caption_color = process_color($slide->img_original_color, 'nivo');
							
						else 
							$caption_color = $slide->img_color;
					}
					else 
						$caption_color = get_option('theme_color');
					
					if ( $slide->title != 'no_title' || $slide->text != 'no_text' )
					{
						$slider .= '<div id="'.$slide->id.'" class="nivo-html-caption">';
					}
					if ( $slide->title != 'no_title' ) $slider .= '<div class="caption_title" style="color: #'.$caption_color.' !important;">'.$slide->title.'</div>';
					if ( $slide->text != 'no_text' ) $slider .= '<div class="caption_text">'.html_entity_decode($slide->text).'</div>';
						
					if ( $slide->title != 'no_title' || $slide->text != 'no_text' )
					{
						$slider .= '</div> <!-- end #htmlcaption -->';
					}
				}  // END foreach 
			
			$slider .= '</div> <!-- end #slider_wrapper -->';
		
		## here we write the big thumbnails ( carousel )
		if ( get_option('nivo_thumbnails') == 'on' )  
		{
			$slider .= '<div id="thumbnail_carousel">';
				$slider .= '<div id="thumbnail_wrapper">';
					$slider .= '<div id="thumbnail_carousel_prev"></div>';
					$slider .= '<ul>';
	
						$thumbnail_counter = 0;
						foreach ( $display_slides as $slide )
						{
							$slider .= '<li>';
								$slider .= '<a class="nivo-control" rel="'.$thumbnail_counter.'" >';
									$slider .= '<img src="'.get_template_directory_uri().'/includes/timthumb.php?src='.$slide->img.'&amp;h=120&amp;w=96&amp;zc=1&amp;q=100" ';   // sau 72 x 128 (wide)
									$slider .= 'alt="'.$slide->title.'" />';
								$slider .= '</a>';
							$slider .= '</li>';
							
							$thumbnail_counter++;
						}
		
					$slider .= '</ul>';
					$slider .= '<div id="thumbnail_carousel_next"></div>';
				$slider .= '</div>';
			$slider .= '</div>';
		}
		
		## here we write the big thumbnails ( carousel )
		if ( get_option('nivo_thumbnails') == 'off' )  
		{
			$slider .= '<div class="nivo_small_thumbnails">';
				$thumbnail_counter = 0;
					foreach ( $display_slides as $slide )
					{
						$slider .= '<a rel="'.$thumbnail_counter.'" >';
							$slider .= $thumbnail_counter;
						$slider .= '</a>';
						
						$thumbnail_counter++;
					}
			$slider .= '</div>';
		}

		$slider .= '</div></section><!-- end #slider -->';
		
	}
	///////////////     nivo_slider END     ///////////////
	
	
	if ( $type == 'bx_slider' )
	{   ###############     bx slider BEGIN     ###############
		
		$position_class = get_option('content_position', 'right_alignment');
		if ( $position_class == '' )
			$position_class = 'right_alignment';
		
		$bx_bg_class = ' bx_left_bg';
		if ( $position_class == 'right_alignment' )
			$bx_bg_class = ' bx_right_bg';
		
		$slider = '<section id="slider">';
			$slider .= '<div class="content_slider'.$bx_bg_class.'">';
				$slider .= '<ul class="bx_slider clearfix">';
				
				foreach ( $display_slides as $slide )
				{
					$slider .= '<li class="clearfix">';
						//begin colores
						
						if ( get_option('slider_color') == 'individual_color' && $slide->img_original_color != '' )
						{
							if ( $slide->img_original_color	== $slide->img_color )
								$caption_color = process_color($slide->img_original_color, 'nivo');
								
							else 
								$caption_color = $slide->img_color;
						}
						else 
							$caption_color = get_option('theme_color');
						
						// end colores		
						
						$button_type    = get_option('content_slider_button_type', 'link');
						
						$slider .= '<div class="bx_content_wrapper '.$position_class.'">';
							$slider .= '<div class="bx_content">';
								if ( $slide->title != 'no_title' ) $slider .= '<h3 style="color: #'.$caption_color.' !important;">'.$slide->title.'</h3>';
								if ( $slide->second_title != 'no_second_title' ) $slider .= '<h4>'.$slide->second_title.'</h4>';
								
								if ( $slide->text != 'no_text' ) $slider .= '<div class="content_text">'.html_entity_decode($slide->text).'</div>';
								
								if ( $slide->link != 'no_link' )
								{
									if ( $button_type ==  'link' )
									{		
										$slider .= '<div class="read_more">';
											$slider .= '<a href="'.$slide->link.'" style="color: #'.$caption_color.';">';
												$slider .= '<span class="read_more_arrow"></span>';
												$slider .= 'Read More';
											$slider .= '</a>';
										$slider .= '</div>';
									}
									
									if ( $button_type ==  'button' )
									{		
										$slider .= '<div class="read_more_button">';
											$slider .= '<a href="'.$slide->link.'" style="color: #'.$caption_color.';">';
												$slider .= 'Read More';
											$slider .= '</a>';
										$slider .= '</div>';
									}
								}
							
							$slider .= '</div>'; // end .bx_content
						$slider .= '</div>'; // end .bx_content_wrapper
						
						$slider .= '<img src="';
						$slider .= get_template_directory_uri();
						$slider .= '/includes/timthumb.php?src=';
						$slider .= $slide->img;
						$slider .= '&amp;h=385&amp;w=624&amp;zc=1&amp;q=100"';
						$slider .= ' alt="'.$slide->title.'" />';
					$slider .= '</li>';
				}
				$slider .= '</ul>';
				
			if ( get_option('layout_style', 'full_width') == 'boxed')
			{
				$button_prev_style = ' style="left: 336px;"';
				$button_next_style = '';
				
				if ( $position_class == 'right_alignment' )
				{
					$button_prev_style = '';
					$button_next_style = ' style="right: 336px;"';
				}
					
				$slider .= '<a class="bx-prev-boxed" href=""'.$button_prev_style.'>prev</a>';
				$slider .= '<a class="bx-next-boxed" href=""'.$button_next_style.'>next</a>';
			}
			
			else 
			{
				$slider .= '<a class="bx-prev" href="">prev</a>';
				$slider .= '<a class="bx-next" href="">next</a>';
			}
			
			$slider .= '</div> <!-- .content_slider -->';
		$slider .= '</section></div>';
	
	}     ///////////////     bx slider END     ///////////////
	
	
	if ( $type == 'carousel' )
	{
	###############     carousel BEGIN     ###############
	
		if ( get_option ('carousel_border') == 'off' || get_option('carousel_border') == '' )
			$carousel_class = 'big_carousel_no_border';
		else
			$carousel_class = 'big_carousel_with_border';
		
		$carousel_size = get_option('carousel_size');
		
		if ( $carousel_size == 'custom' )
		{
			$carousel_image_width  = get_option('carousel_width', '250');
			$carousel_image_height = get_option('carousel_height', '350');
			
			if ( $carousel_image_width  == '' ) $carousel_image_width  = 350;
			if ( $carousel_image_height == '' ) $carousel_image_height = 350;
			
			$carousel_image_width  = str_replace( 'px', '', $carousel_image_width );
			$carousel_image_height = str_replace( 'px', '', $carousel_image_height );
			
			$carousel_image_size = 'w='.$carousel_image_width.'&amp;h='.$carousel_image_height;
			
			$carousel_width  = (int)($carousel_image_width);
			$carousel_height = (int)($carousel_image_height);
		}
		
		else 
		{
			if ( $carousel_size == 'tall' )
			{
				$carousel_image_size = 'w=250&amp;h=350';
				$carousel_width  = '250';
				$carousel_height = '350';
			}
			if ( $carousel_size == 'square' )
			{
				$carousel_image_size = 'w=350&amp;h=350';
				$carousel_width  = '350';
				$carousel_height = '350';
			}
			if ( $carousel_size == 'wide' )
			{
				$carousel_image_size = 'w=500&amp;h=350';
				$carousel_width  = '500';
				$carousel_height = '350';
			}
		}
		
		if ( get_option('carousel_border') == 'on' )
		{
			$carousel_width  += 10;
			$carousel_height += 10;
		}

		$carousel_width_style  = 'style="width: '.$carousel_width.'px !important;"';
		$carousel_height_style = 'style="height: '.$carousel_height.'px !important;"';
		
		$slider = '<section id="slider">';
			$slider .= '<div id="big_carousel_wrapper">';
				$slider .= '<ul id="big_carousel" class="'.$carousel_class.'" '.$carousel_height_style.'>';
				
				foreach ( $display_slides as $slide )
				{
					//begin colores
					if ( get_option('slider_color') == 'individual_color' && $slide->img_original_color != '' )
					{
						if ( $slide->img_original_color	== $slide->img_color )
							$caption_color = process_color($slide->img_original_color, 'nivo');
							
						else 
							$caption_color = $slide->img_color;
					}
					else 
						$caption_color = get_option('theme_color');
					// end colores		
					
					$slider .= '<li '.$carousel_width_style.'>';
						$slider .= '<div class="content">';
						
							if ( $slide->target == 'link' && $slide->link != 'no_link' )
							{
								$slider .= '<a href="'.$slide->link.'">';
								$link_exists = true;
							}
							
							if ( $slide->target == 'image' && $slide->img != 'no_image' )
							{
								$slider .= '<a href="'.$slide->img.'">';
								$link_exists = true;
							}
							
							if ( $slide->target == 'video' && $slide->video != 'no_video' )
							{
								$slider .= '<a href="'.$slide->video.'">';
								$link_exists = true;
							}
							
							$slider .= '<div class="slide_image">';
								$slider .= '<img src="';
								$slider .= get_template_directory_uri();
								$slider .= '/includes/timthumb.php?src=';
								$slider .= $slide->img;
								$slider .= '&amp;'.$carousel_image_size.'&amp;zc=1&amp;q=100"';
								$slider .= ' alt="'.$slide->title.'" />';
								
								$slider .= '<div class="title" style="background-color: #'.$caption_color.' !important;"><h3>'.$slide->title.'</h3></div>';
							$slider .= '</div>';
							
							if ( $link_exists )
							{
								$slider .= '</a>';
							}
						$slider .= '</div>'; // end .content
					$slider .= '</li>';
				}
				$slider .= '</ul>';

				$slider .= '<a id="big_carousel_prev" href="#">prev</a>';
				$slider .= '<a id="big_carousel_next" href="#">next</a>';
			
			$slider .= '</div> <!-- end of #big_carousel_wrapper -->';
			
		$slider .= '</section>';
	}
	///////////////    carousel END     ///////////////
	
	
	###############     wide_slider BEGIN     ###############
	
	
	if ( $type == 'wide_slider' && count($display_slides) > 2 )
	{
		$wide_slider_img_size = 'h=280&amp;w=462';
		
		$slider = '<section id="slider" style="margin-bottom: 35px !important;">';
			$slider .= '<div class="wide_slider clearfix">';
				$slider .= '<ul>';
	
			$as_many_times = 0;
			$double_it = 1;
			if ( count($display_slides) == 3 || count($display_slides) == 4 ) $double_it++;
			
			while ( $as_many_times != $double_it ):
				for ( $i = count($display_slides)-2; $i < count($display_slides); $i++ )  // the last two 
				{
					$slider .= '<li>';
					
					//begin colores
					if ( get_option('slider_color') == 'individual_color' && $display_slides[$i]->img_original_color != '' )
					{
						if ( $display_slides[$i]->img_original_color == $display_slides[$i]->img_color )
							$caption_color = process_color($display_slides[$i]->img_original_color, 'nivo');
							
						else 
							$caption_color = $display_slides[$i]->img_color;
					}
					else 
						$caption_color = get_option('theme_color');
					//end colores	
										
						$slider .= '<div class="slide_image">';
							$slider .= '<img src="';
							$slider .= get_template_directory_uri();
							$slider .= '/includes/timthumb.php?src=';
							$slider .= $display_slides[$i]->img;
							$slider .= '&amp;'.$wide_slider_img_size.'&amp;zc=1&amp;q=100"';
							$slider .= ' alt="'.$display_slides[$i]->title.'" />';
						$slider .='</div>';
						
						$slider .= '<div class="info-container" style="display:none">';
							
							$slider .= '<div class="slide_title" style="color: #'.$caption_color.' !important;">';
								if ( $display_slides[$i]->title != 'no_title' ) $slider .= $display_slides[$i]->title;
								else $slider .= 'No Title';
							$slider .= '</div>';
							$slider .= '<div class="slide_description">';
								if ( $display_slides[$i]->text != 'no_text' ) $slider .= html_entity_decode($display_slides[$i]->text);
								else $slider .= 'No Description';
							$slider .= '</div>';
							if ( $display_slides[$i]->target == 'link' && $display_slides[$i]->link != 'no_link' )
							{
								$slider .= '<a href="'.$display_slides[$i]->link.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
							if ( $display_slides[$i]->target == 'image' && $display_slides[$i]->img != 'no_image' )
							{
								$slider .= '<a href="'.$display_slides[$i]->img.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
							if ( $display_slides[$i]->target == 'video' && $display_slides[$i]->video != 'no_video' )
							{
								$slider .= '<a href="'.$display_slides[$i]->video.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
						$slider .= '</div> <!-- end of .info-container -->';
					$slider .= '</li>';
				}
				
				for ( $i = 0; $i < count($display_slides)-2; $i++ )  //  from the first to the last ( except the last two )
				{
					$slider .= '<li>';
					
					//begin colores
					if ( get_option('slider_color') == 'individual_color' && $display_slides[$i]->img_original_color != '' )
					{
						if ( $display_slides[$i]->img_original_color == $display_slides[$i]->img_color )
							$caption_color = process_color($display_slides[$i]->img_original_color, 'nivo');
							
						else 
							$caption_color = $display_slides[$i]->img_color;
					}
					else 
						$caption_color = get_option('theme_color');
					//end colores	
					
						$slider .= '<div class="slide_image">';
							$slider .= '<img src="';
							$slider .= get_template_directory_uri();
							$slider .= '/includes/timthumb.php?src=';
							$slider .= $display_slides[$i]->img;
							$slider .= '&amp;'.$wide_slider_img_size.'&amp;zc=1&amp;q=100"';
							$slider .= ' alt="'.$display_slides[$i]->title.'" />';
						$slider .='</div>';
						
						$slider .= '<div class="info-container" style="display:none">';
							
							$slider .= '<div class="slide_title" style="color: #'.$caption_color.' !important;">';
								if ( $display_slides[$i]->title != 'no_title' ) $slider .= $display_slides[$i]->title;
								else $slider .= 'No Title';
							$slider .= '</div>';
							$slider .= '<div class="slide_description">';
								if ( $display_slides[$i]->text != 'no_text' ) $slider .= html_entity_decode($display_slides[$i]->text);
								else $slider .= 'No Description';
							$slider .= '</div>';
							if ( $display_slides[$i]->target == 'link' && $display_slides[$i]->link != 'no_link' )
							{
								$slider .= '<a href="'.$display_slides[$i]->link.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
							if ( $display_slides[$i]->target == 'image' && $display_slides[$i]->img != 'no_image' )
							{
								$slider .= '<a href="'.$display_slides[$i]->img.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
							if ( $display_slides[$i]->target == 'video' && $display_slides[$i]->video != 'no_video' )
							{
								$slider .= '<a href="'.$display_slides[$i]->video.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
	
						$slider .= '</div> <!-- end of .info-container -->';
					$slider .= '</li>';
				}
				
				$as_many_times++;
				
			endwhile;
			
				$slider .='</ul>';
			$slider .='</div> <!-- end of #fw_slider -->';
		$slider .='</section> <!-- end of #slider -->';
			
		$slider .= '<div id="wide_slider_frame">';
			$slider .= '<div id="wide_slider_tools_wrapper">';
				$slider .= '<div id="title_description">';
					$slider .= '<div class="project-slider">';
						$slider .= '<div class="info-container">';
							
							//begin colores
							if ( get_option('slider_color') == 'individual_color' && $display_slides[0]->img_original_color != '' )
							{
								if ( $display_slides[0]->img_original_color == $display_slides[0]->img_color )
									$caption_color = process_color($display_slides[0]->img_original_color, 'nivo');
									
								else 
									$caption_color = $display_slides[0]->img_color;
							}
							else 
								$caption_color = get_option('theme_color');
							//end colores	
							
							$slider .= '<div class="slide_title" style="color: #'.$caption_color.' !important;">';
								if ( $display_slides[0]->title != 'no_title' ) $slider .= $display_slides[0]->title;
								else $slider .= 'No Title';
							$slider .= '</div>';
							$slider .= '<div class="slide_description">';
								if ( $display_slides[0]->text != 'no_text' ) $slider .= html_entity_decode($display_slides[0]->text);
								else $slider .= 'No Description';
							$slider .= '</div>';
							
							if ( $display_slides[0]->target == 'link' && $display_slides[0]->link != 'no_link' )
							{
								$slider .= '<a href="'.$display_slides[0]->link.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
							if ( $display_slides[0]->target == 'image' && $display_slides[0]->img != 'no_image' )
							{
								$slider .= '<a href="'.$display_slides[0]->img.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
							
							if ( $display_slides[0]->target == 'video' && $display_slides[0]->video != 'no_video' )
							{
								$slider .= '<a href="'.$display_slides[0]->video.'"><div class="slide_link"><div class="arrow" style="background-color: #'.$caption_color.' !important"></div>Read More</div></a>';
							}
	
						$slider .= '</div> <!-- end of .info-container -->';
					$slider .= '</div> <!-- end of .project-slider -->';
				$slider .= '</div> <!-- end of #title_description -->';
				$slider .= '<div class="wide_slider_navi">';
					$slider .= '<a class="back"></a>';
					$slider .= '<a class="foward"></a>';
				$slider .= '</div>';
			$slider .= '</div> <!-- end of #wide_slider_tools_wrapper -->';
		$slider .= '</div> <!-- end of #wide_slider_frame -->';	
	}
	
	///////////////    wide_slider END     ///////////////


	if ( $type == 'piecemaker' )
	{
	###############     piecemaker BEGIN     ###############

		$slider = '<section id="slider" style="margin-bottom: 20px !important;">';
			$slider .= '<div id="piecemaker_wrapper">';
				$slider .= '<div id="piecemaker">';
					$slider .= '<p>';
						$slider .= 'You need to <a href="http://www.adobe.com/products/flashplayer/" target="_blank">upgrade your Flash Player</a> to version 10 or newer.';
					$slider .= '</p>';
				$slider .= '</div>';
			$slider .= '</div>';
		$slider .= '</section>';
	}
	///////////////    piecemaker END     ///////////////

	
	if ( $type == 'accordion_slider' && $count_slides >= 3 )
	{
	###############     accordion_slider BEGIN     ###############
		
		$slider = '<section id="slider">';
			$slider .= '<div id="accordion_slider">';		
				$slider .='<ul class="kwicks horizontal">';
	
				if ( $count_slides > 6 ) $count_slides = 6;
				$kwicks_displayed = 0;
						
				$number_of_elements_class = 'with_'.$count_slides.'_elements';
				
					foreach ( $display_slides as $slide )
					{
						
						/// colores start
						
						if ( get_option('slider_color') == 'individual_color' && $slide->img_original_color != '' )
						{
							if ( $slide->img_original_color	== $slide->img_color )
								$caption_color = process_color($slide->img_original_color, 'nivo');
								
							else 
								$caption_color = $slide->img_color;
						}
						else 
							$caption_color = get_option('theme_color');
						
						///  colores end
						
						$kwicks_displayed++;
						
						$slider .= '<li class="'.$number_of_elements_class.'">';
							if ( $slide->target == 'link' && $slide->link != 'no_link' )
							{
								$slider .= '<a href="'.$slide->link.'">';
								$link_exists = true;
							}
							
							if ( $slide->target == 'image' && $slide->img != 'no_image' )
							{
								$slider .= '<a href="'.$slide->img.'">';
								$link_exists = true;
							}
							
							if ( $slide->target == 'video' && $slide->video != 'no_video' )
							{
								$slider .= '<a href="'.$slide->video.'">';
								$link_exists = true;
							}
							
							// The Caption
							if ( $slide->title != 'no_title' || $slide->text != 'no_text' )
							{
								$slider .= '<div id="'.$slide->id.'" class="accordion_caption" style="opacity: 0;">';
									$slider .= '<div class="accordion_wrapper">';
							}
									if ( $slide->title != 'no_title' ) $slider .= '<div class="caption_title" style="color: #'.$caption_color.' !important;">'.$slide->title.'</div>';
									if ( $slide->text != 'no_text' ) $slider .= '<div class="caption_text">'.$slide->text.'</div>';
									
							if ( $slide->title != 'no_title' || $slide->text != 'no_text' )
							{
									$slider .= '</div>';
								$slider .= '</div> <!-- end #htmlcaption -->';
							}
												
							// The Image
							$slider .= '<div class="slide_image">';
								$slider .= '<img src="';
								$slider .= get_template_directory_uri();
								$slider .= '/includes/timthumb.php?src=';
								$slider .= $slide->img;
								$slider .= '&amp;h=385&amp;w=640&amp;zc=1&amp;q=100"';
								$slider .= ' alt="'.$slide->title.'" />';
							$slider .='</div>';
							
							if ( $link_exists )
							{
								$slider .= '</a>';
							}
						$slider .= '</li>';
						if ( $kwicks_displayed == $count_slides ) break;
					}
				$slider .= '</ul>';
			$slider .= '</div> <!-- end of #accordion_slider -->';
		$slider .= '</section> <!-- end of #slider -->';
	
	}
	///////////////    accordion_slider END     ///////////////
	
	
	if ( $type == 'complex_slider' && $count_slides >= 3 )
	{
	###############     complex_slider BEGIN     ###############
	
		$type = array( 1 => array( 
									0 => 'small',
									1 => 'small',
									2 => 'wide',
									3 => 'wide'
								   ),
					  
					   2 => array( 
									0 => 'big',
									1 => 'small',
									2 => 'small'
								   ),
					   
					   3 => array( 
									0 => 'wide',
									1 => 'small',
									2 => 'small',
									3 => 'wide'
								   ),
					   
					   4 => array( 
									0 => 'wide',
									1 => 'big'
								   ),
					   
					   5 => array( 
									0 => 'big',
									1 => 'wide'
								   ),
					   
					   6 => array( 
									0 => 'small',
									1 => 'small',
									2 => 'big'
								   ),
					   
					   7 => array( 
									0 => 'wide',
									1 => 'wide',
									2 => 'small',
									3 => 'small'
								   )
					  );
		
		$counter [0] = 4;
		$counter [1] = 3;
		$counter [2] = 4;
		$counter [3] = 2;
		$counter [4] = 2;
		$counter [5] = 3;
		$counter [6] = 4;
		
		$slider = '<section id="slider">';
			$slider .= '<div id="complex_slider">';
				$slider .= '<ul>';
			
				$type_counter = 0;
				$which_type = 1;
				
				$slides_added = 0;
				
				for($kkk=0; $kkk<5; $kkk++)
				foreach ( $display_slides as $slide )
				{
					if ( $type_counter % count($type[$which_type]) == 0 ) $slider .= '<li>';
					
						$element_class = $type[$which_type][$type_counter];
						$slider .=  '<div class="complex_element '.$element_class.'">';
							
							if ( $type[$which_type][$type_counter] == 'small' ) 
							{
								$thumbnail_size = 'w=158&amp;h=158';
								$item_size = 'width: 158px; height: 158px;';
							}
							
							if ( $type[$which_type][$type_counter] == 'wide' )
							{
								$thumbnail_size = 'w=318&amp;h=158';
								$item_size = 'width: 318px; height: 158px;';
							}
							
							if ( $type[$which_type][$type_counter] == 'big' )
							{
								$thumbnail_size = 'w=318&amp;h=318';
								$item_size = 'width: 318px; height: 318px;';
							}
							
							$image_source = get_template_directory_uri().'/includes/timthumb.php?src='.$slide->img.'&amp;'.$thumbnail_size.'&amp;zc=1&amp;q=100';
							$image_background_source = get_template_directory_uri().'/includes/timthumb.php?src='.$slide->img.'&amp;'.$thumbnail_size.'&amp;zc=1&amp;q=100&amp;f=2|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8|8';
							
							$slider .= '<a href="'.$slide->link.'" style="'.$item_size.'">';
								$slider .= '<div class="content_wrapper" style="'.$item_size.'">';
									$slider .= '<div class="content" style="'.$item_size.'">';
										$slider .= '<h4>';
											$slider .= $slide->title;
										$slider .= '</h4>';
										if ( $slide->second_title != 'no_second_title' )
										{
											$slider .= '<div class="text">';
												$slider .= $slide->second_title;
											$slider .= '</div>';
										}
									$slider .= '</div>';
								$slider .= '</div>';
								
								$slider .= '<img class="image" style="display: block; '.$item_size.'" src="'.$image_source.'" alt="'; 
								$slider .= get_the_title();
								$slider .= '" />';
							$slider .= '</a>';
							
						$slider .=  '</div>';
					if ( $type_counter % count($type[$which_type]) == count($type[$which_type]) - 1 || $slides_added == 5 * $count_slides - 1 ) $slider .= '</li>';
					
					$type_counter++;
					
					if ( $type_counter == count($type[$which_type]) )
					{
						$which_type++;
						$type_counter = 0;
					}
	
					if ( $which_type == 8 ) $which_type = 1;
					$slides_added++;
				}
			
				$slider .= '</ul>';
			$slider .= '</div> <!-- end of #complex_slider -->';
		$slider .= '</section>';
	
	}
	///////////////    complex_slider END     ///////////////
	
echo $slider;

}
///////////////     write_slider END     ///////////////

//add slder left menu
register_nav_menus( array(
	'slider_left' => 'Slider left menu ,Plz Make sure item num = 9',
) );


/////////////////////////////////////////////
//               End BY Michael            //
/////////////////////////////////////////////